package com.mine.modules.vm.controller;


import com.mine.modules.vm.domain.dto.AddOrEditAssetDto;
import com.mine.modules.vm.domain.dto.AssetsImportDto;
import com.mine.modules.vm.domain.dto.BindingSensor;
import com.mine.modules.vm.domain.query.AssetsPageQuery;
import com.mine.common.domain.vo.Result;
import com.mine.modules.vm.entity.VmAssets;
import com.mine.modules.vm.service.IVmAssetsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author xujf
 * @since 2024-09-21
 */
@RestController
@RequestMapping("/vm-assets")
@RequiredArgsConstructor
@Api(tags = "固定资产")
public class VmAssetsController {

    private final IVmAssetsService assetsService;

    @ApiOperation(value = "分页获取设备列表", notes = "分页获取设备列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<?> queryPageList(AssetsPageQuery assetsPageQuery) {
        return assetsService.queryPageList(assetsPageQuery);
    }

    @ApiOperation(value = "获取设备详细信息", notes = "获取设备详细信息")
    @RequestMapping(value = "/getByNumber", method = RequestMethod.GET)
    @ApiImplicitParam(name = "assetNumber", value = "资产编码", required = true)
    public Result<VmAssets> getByNumber(@RequestParam(name = "assetNumber", required = true) String assetNumber) {
        return assetsService.getByNumber(assetNumber);
    }

    @ApiOperation(value = "添加或编辑", notes = "添加或编辑")
    @RequestMapping(value = "/addOrEdit", method = {RequestMethod.POST})
    public Result<?> addOrEdit(AddOrEditAssetDto vmAsset) {
        return assetsService.addOrEdit(vmAsset);
    }

    @ApiOperation(value = "删除", notes = "删除")
    @RequestMapping(value = "/delete", method = {RequestMethod.GET})
    public Result<?> delete(@RequestParam String id) {
        return assetsService.delete(id);
    }

    @ApiOperation(value = "批量删除", notes = "批量删除")
    @RequestMapping(value = "/deleteBatch", method = {RequestMethod.GET})
    public Result<?> deleteBatch(@RequestParam String ids) {
        return assetsService.deleteBatch(ids);
    }

    @ApiOperation(value = "查询所有安装位置", notes = "查询所有安装位置")
    @RequestMapping(value = "/listAllLocation", method = RequestMethod.GET)
    public Result<?> listAllLocation(String layerId, String keywords) {
        return assetsService.listAllLocation(layerId, keywords);
    }

    @ApiOperation(value = "查询所有设备类别", notes = "查询所有设备类别")
    @RequestMapping(value = "/listAllAssetClassify", method = RequestMethod.GET)
    public Result<?> listAllAssetClassify(String layerId, String keywords) {
        return assetsService.listAllAssetClassify(layerId, keywords);
    }

    @ApiOperation(value = "查询所有设备用途", notes = "查询所有设备用途")
    @RequestMapping(value = "/listAllPurpose", method = RequestMethod.GET)
    public Result<?> listAllPurpose(String layerId, String keywords) {
        return assetsService.listAllPurpose(layerId, keywords);
    }

//    @ApiOperation(value = "设备安装区域统计", notes = "设备安装区域统计")
//    @RequestMapping(value = "/getCountByRegions", method = {RequestMethod.GET})
//    public Result<?> getCountByRegions() {
//        return assetsService.getCountByRegions();
//    }

    @ApiOperation(value = "批量新增设备下传感器", notes = "批量新增设备下传感器")
    @RequestMapping(value = "/batchBindingSensorByDeviceId", method = {RequestMethod.POST})
    public Result<?> batchBindingSensorByDeviceId(BindingSensor bindingSensor) {
        return assetsService.batchBindingSensorByDeviceId(bindingSensor);
    }

    @ApiOperation(value = "批量删除设备下传感器", notes = "批量删除设备下传感器")
    @RequestMapping(value = "/batchDeleteSensorByDeviceId", method = {RequestMethod.POST})
    public Result<?> batchDeleteSensorByDeviceId(BindingSensor bindingSensor) {
        return assetsService.batchDeleteSensorByDeviceId(bindingSensor);
    }

    @ApiOperation(value = "绑定设备场景图层id", notes = "绑定设备场景图层id")
    @RequestMapping(value = "/bindSceneLayerOfAssets", method = {RequestMethod.GET})
    public Result<?> bindSceneLayerOfAssets(@RequestParam String deviceId, @RequestParam(required = false) String sceneLayerId) {
        return assetsService.bindSceneLayerOfAssets(deviceId, sceneLayerId);
    }

    @ApiOperation(value = "通过场景图层id查询设备详情", notes = "通过场景图层id查询设备详情")
    @RequestMapping(value = "/getDetailsBySceneLayerId", method = {RequestMethod.GET})
    public Result<?> getDetailsBySceneLayerId(@RequestParam String sceneLayerId) {
        return assetsService.getDetailsBySceneLayerId(sceneLayerId);
    }

    @ApiOperation(value = "通过id查询设备详情", notes = "通过id查询设备详情")
    @RequestMapping(value = "/getDetailsById", method = {RequestMethod.GET})
    public Result<?> getDetailsById(@RequestParam String id, @RequestParam(required = false) String layerId) {
        return assetsService.getDetailsById(id, layerId);
    }

    @ApiOperation(value = "设备参数统计", notes = "设备参数统计")
    @RequestMapping(value = "/parametricStatistical", method = {RequestMethod.GET})
    public Result<?> parametricStatistical(@RequestParam String type, @RequestParam(required = false) String layerId) {
        return assetsService.parametricStatistical(type, layerId);
    }

    @ApiOperation(value = "设置视角", notes = "设置视角")
    @RequestMapping(value = "/setAngleView", method = {RequestMethod.GET})
    public Result<?> setAngleView(@RequestParam String id, @RequestParam(required = false) String angleView) {
        return assetsService.setAngleView(id, angleView);
    }

    @ApiOperation(value = "导入数据", notes = "导入数据")
    @PostMapping(value = "/importExcel")
    public Result<?> importExcel(AssetsImportDto assetsFile) {
        return assetsService.importExcel(assetsFile.getFile());
    }

}
